/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chalmers.se.tda367.database;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import edu.chalmers.se.tda367.observer.GlobalObserverList;
import edu.chalmers.se.tda367.model.User;

/**
 *
 * @author pierrereimertz
 */
public class Database implements PropertyChangeListener {

    public final String url = "database/pictures/";
    private String tempDbFileString = "";
    private List<User> database = null;
    private static final Database INSTANCE = new Database();
    private GlobalObserverList o = GlobalObserverList.getInstance();

    private Database() {
        o.addObserver(this);
    }

    public List<User> getDatabase() {
        return database;
    }

    public void add(User user) {
        database.add(user);
        o.firePropertyChange("Database.NewUser", null, user);
    }

    public String getTempDbFileString() {
        return tempDbFileString;
    }

    public void addToTempDbFileString(String s) {
        tempDbFileString += s;
    }

    public static Database getInstance() {

        return INSTANCE;
    }

    public void propertyChange(PropertyChangeEvent pce) {
    }

    public void setDatabase(List<User> tdb) {
        //För att inte kunna ändra databasen mer än en gång
        //Nu sätter vi databasen ifrån PluggisInitiator
        if (database == null) {
            database = tdb;
        }

    }

    public void resetTempFile() {
        tempDbFileString = "";
    }

    public void remove(int i) {
        database.remove(i);

    }
}
